"""
课后作业
通过datetime模块完成时间戳, datetime.datetime对象, 格式化字符串三者之间的转换
封装一个函数get_date(day_delta), 如果传入的是-1 , 输出就是字符串日期2020-01-02.
"""


"""
时间转字符串
2021-01-05
 22:54:37
2021-01-05 22:54:37
"""
time=datetime.datetime.today()
#print(time.strftime("%Y-%m-%d"))
#print(time.strftime(" %H:%M:%S"))
#print(time.strftime("%Y-%m-%d %H:%M:%S"))

"""
字符串转时间
"""
str='22:54:37'
str2='2021-01-06'
#print(datetime.datetime.strptime(str2,"%Y-%m-%d"))
#print(datetime.datetime.strptime(str,"%H:%M:%S"))

"""
时间转时间戳
"""
time2=datetime.datetime.today()
#print(time2.timestamp())

"""
时间戳 转时间
1609858686.217262
"""
ts=1609858686.217262
#print(datetime.datetime.fromtimestamp(ts,tz=None))


from datetime import timedelta

"""
2021-01-02 23:05:05.400499
封装一个函数get_date(day_delta), 如果传入的是-1 , 输出就是字符串日期2020-01-02.

"""



def get_date(day_delta):
    wow = datetime.datetime.today()
    if day_delta==-1:
        wow+=timedelta(days=-3)
        wow= datetime.datetime.strftime(wow,"%Y-%m-%d")
    else:
        wow = datetime.datetime.strftime(wow, "%Y-%m-%d")

    return wow

print(get_date(-1))
